package domain.DAO;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.FetchMode;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import domain.Contact;
import domain.Entreprise;
import domain.interfaces.IDAOEntreprise;

public class DAOEntreprise extends DAOCrud<Entreprise> implements
		IDAOEntreprise {

	public DAOEntreprise() {
		super(Entreprise.class);
	}

	@Override
	public Entreprise find(long id) {
		hibernateTemplate.setCacheQueries(true);
		DetachedCriteria query = DetachedCriteria.forClass(this.entityClass)
				.add(Restrictions.idEq(id)).setFetchMode("add", FetchMode.JOIN)
				.setFetchMode("books", FetchMode.JOIN)
				.setFetchMode("phones", FetchMode.JOIN);
		hibernateTemplate.setCacheQueries(false);
		return (Entreprise) hibernateTemplate.findByCriteria(query).get(0);
	}
}
